package cn.tianyun.pethome.org.service.impl;

import cn.tianyun.pethome.basic.base.service.impl.BaseServiceImpl;
import cn.tianyun.pethome.basic.util.BaseConstants;
import cn.tianyun.pethome.org.domain.Logininfo;
import cn.tianyun.pethome.org.domain.User;
import cn.tianyun.pethome.org.mapper.LogininfoMapper;
import cn.tianyun.pethome.org.mapper.UserMapper;
import cn.tianyun.pethome.org.service.IUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author tianyun
 * @since 2023-02-27
 */
@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private LogininfoMapper logininfoMapper;
    @Override
    public void add(User user){
        //添加的用户的时候要同步Logininfo
        Logininfo logininfo = new Logininfo();
        logininfo.setDisable(BaseConstants.Logininfo.STATE_DISABLE_TRUE);
        logininfo.setType(BaseConstants.Logininfo.STATE_TYPE_USER);
        BeanUtils.copyProperties(user,logininfo);
        logininfoMapper.add(logininfo);
        user.setLogininfoId(logininfo.getId());
        super.add(user);
    }

    @Override
    public User loadByPhone(String phone) {
        return userMapper.loadByPhone(phone);
    }

    @Override
    public User loadByLogininfo(Long id) {
       User  user= userMapper.loadByLogininfo(id);
        return user;
    }
}
